import { _decorator, Component, Node, resources, Sprite, SpriteFrame } from 'cc';
import { LayerBase } from './LayerBase';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { AudioMgr } from '../utils/AudioMgr';
const { ccclass, property } = _decorator;

@ccclass('SetPanel')
export class SetPanel extends LayerBase {

    @property(Sprite)
    audioBgmToggleImg: Sprite;
    @property(Sprite)
    audioEffectToggleImg: Sprite;

    init(somedData?: any): void {
        if (AudioMgr.ins.isAudioBgm) {
            resources.load("UIImg/audioOpen/spriteFrame", SpriteFrame, (err, res) => {
                this.audioBgmToggleImg.spriteFrame = res;
            })
        }
        else {
            resources.load("UIImg/audioClose/spriteFrame", SpriteFrame, (err, res) => {
                this.audioBgmToggleImg.spriteFrame = res;
            })
        }

        if (AudioMgr.ins.isAudioEffect) {
            resources.load("UIImg/audioOpen/spriteFrame", SpriteFrame, (err, res) => {
                this.audioEffectToggleImg.spriteFrame = res;
            })
        }
        else {
            resources.load("UIImg/audioClose/spriteFrame", SpriteFrame, (err, res) => {
                this.audioEffectToggleImg.spriteFrame = res;
            })
        }
    }

    onclickAudioBtn(){
        if (AudioMgr.ins.isAudioBgm) {
            AudioMgr.ins.isAudioBgm=false;
            AudioMgr.ins.stop();
            resources.load("UIImg/audioClose/spriteFrame", SpriteFrame, (err, res) => {
                this.audioBgmToggleImg.spriteFrame = res;
            })
        }
        else{
            AudioMgr.ins.isAudioBgm=true;
            AudioMgr.ins.play("audio/bgm0");
            resources.load("UIImg/audioOpen/spriteFrame", SpriteFrame, (err, res) => {
                this.audioBgmToggleImg.spriteFrame = res;
            })
        }
    }

    onclickAudioEffectBtn(){
        if (AudioMgr.ins.isAudioEffect) {
            AudioMgr.ins.isAudioEffect=false;
            resources.load("UIImg/audioClose/spriteFrame", SpriteFrame, (err, res) => {
                this.audioEffectToggleImg.spriteFrame = res;
            })
        }
        else{
            AudioMgr.ins.isAudioEffect=true;
            resources.load("UIImg/audioOpen/spriteFrame", SpriteFrame, (err, res) => {
                this.audioEffectToggleImg.spriteFrame = res;
            })
        }
    }

}


